/**
 * This class contains unit tests for validating the behavior of Apex classes
 * and triggers.
 *
 * Unit tests are class methods that verify whether a particular piece
 * of code is working properly. Unit test methods take no arguments,
 * commit no data to the database, and are flagged with the testMethod
 * keyword in the method definition.
 *
 * All test methods in an organization are executed whenever Apex code is deployed
 * to a production organization to confirm correctness, ensure code
 * coverage, and prevent regressions. All Apex classes are
 * required to have at least 75% code coverage in order to be deployed
 * to a production organization. In addition, all triggers must have some code coverage.
 *
 * The @isTest class annotation indicates this class only contains test
 * methods. Classes defined with the @isTest annotation do not count against
 * the organization size limit for all Apex scripts.
 *
 * See the Apex Language Reference for more information about Testing and Code Coverage.
 */
@isTest
private class MileageTrackerTestSuite {

    static testMethod void runPositiveTestCases() {
        // TO DO: implement unit test
		Double totalMiles = 0;
		final Double maxtotalMiles= 500;
		final Double singletotalMiles= 300;
		final String createdbyId = UserInfo.getUserId();
		List<Mileage__c> deleteMiles = new List<Mileage__c>();

		System.debug('Setting up testing - deleting any mileage records for today');

		deleteMiles = [SELECT miles__c from Mileage__c
		WHERE createdDate = TODAY and createdById = :createdbyId];

		if(!deleteMiles.isEmpty()) {
			delete deleteMiles;
		}

		System.debug('Inserting 300 more miles...single record validation');

		Mileage__c testMiles1 = new Mileage__c(Miles__c = 300, Date__c = System.today() );
		insert testMiles1;

		for(Mileage__c m:[SELECT miles__c FROM Mileage__c
			WHERE createdDate = TODAY
			and createdById = :createdbyId
			and miles__c != null]) {
				totalMiles += m.miles__c;
		}

		System.assertEquals(singletotalMiles, totalMiles);

		totalMiles = 0;

		System.debug('Inserting 200 Mileage records...bulk validation');

		List<Mileage__c> testMiles2 = new List<Mileage__c>();
		for(integer i=0; i<200; i++){
			testMiles2.add( new Mileage__c(Miles__c = 1, Date__c = System.today()) );
		}
		insert testMiles2;

		for(Mileage__c m:[SELECT miles__c FROM Mileage__c
			WHERE createdDate = TODAY
			and createdById = :createdbyId
			and miles__c != null]) {
				totalMiles += m.miles__c;
		}

		System.assertEquals(maxtotalMiles, totalMiles);

   }
/*
	static testMethod void runNegativeTestCases(){

		System.debug('Inserting 500 miles... negative test case');

		Mileage__c testMiles3 = new Mileage__c(Miles__c = 500, Date__c = System.today());

		try {
			insert testMiles3;
		} catch (DmlException e) {
			//Assert Error Message
			System.assert(e.getMessage().contains('Insert failed. First exception on row 0; '+
			'first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, '+
			'Mileage request exceeds daily limit(500): [Miles__c]'),
			e.getMessage());

			//Assert Field
			System.assertEquals(Mileage__c.Miles__c, e.getDmlFields(0)[0]);
			//Assert Status Code
			System.assertEquals('FIELD_CUSTOM_VALIDATION_EXCEPTION' , e.getDmlStatusCode(0));
		}
	}
	*/
}